package com.fishing.controller;

import QL.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fishing.entity.L_player;
import com.fishing.entity.OperLog;
import com.fishing.service.OperLogService;
import com.fishing.util.JsonUtils;
import com.fishing.util.personal.Playerlist;
import com.fishing.util.personal.RegExrUtils;
import com.fishing.util.personal.SortField;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;

/***
 * 首页
 * @author tgh
 *
 */
@Controller
public class PlayerController{
	
	@Autowired
	private OperLogService operlogService;
	
	private static QLClient client = new QLClient();
	
	//region 玩家信息页面
	@RequestMapping("pa/toList")
	public ModelAndView toList(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/list");
		return mav;
	}
	//endregion
	
	//region 修改玩家昵称
	@RequestMapping("pa/ChangeNicknameview")
	public ModelAndView ChangeNicknameview(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/ChangeNicknameview");
		return mav;
	}
	//endregion
	
	//region 改变绑定手机页面
	@RequestMapping("pa/toChangePhone")
	public ModelAndView toChangePhone(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/ChangePhone");
		return mav;
	}
	//endregion
	
	//region 改变金币密码页面
	@RequestMapping("pa/toChangeBankPassword")
	public ModelAndView toChangeBankPassword(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/ChangeBankPassword");
		return mav;
	}
	//endregion
	
	//region 更改绑定手机密码页面
	@RequestMapping("pa/toupdateAccountResetPhonePassword")
	public ModelAndView toupdateAccountResetPhonePassword(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/UpdateAccountResetPhonePassword");
		return mav;
	}
	//endregion
	
	//region 生产手机页面
	@RequestMapping("pa/AccountPhoneGenerate")
	public ModelAndView AccountPhoneGenerate(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/AccountPhoneGenerate");
		return mav;
	}
	//endregion
	
	//region 批量生产手机号码页面
	@RequestMapping("pa/AccountPhoneBatchGenerate")
	public ModelAndView AccountPhoneBatchGenerate(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/AccountPhoneBatchGenerate");
		return mav;
	}
	//endregion
	
	//region 玩家资源页面
	@RequestMapping("pa/UpdatePlayerResource")
	public ModelAndView UpdatePlayerResource(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/UpdatePlayerResource");
		return mav;
	}
	//endregion
	
	//region 玩家资源日志页面 
	@RequestMapping("pa/UpdatePlayerResourceLog")
	public ModelAndView UpdatePlayerResourceLog(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/UpdatePlayerResourceLog");
		return mav;
	}
	//endregion
	
	//region 插入日志
	public void insertLog(boolean flag, String msg, int type, String eventexplain, String Userid, HttpServletRequest request) throws Exception{
		//插入日志
		OperLog ol = new OperLog();
		ol.setType(type);
		ol.setAdminname((String)request.getSession().getAttribute("Admintruename"));
		ol.setServiceName("玩家调整"+(StringUtils.isEmpty(msg)?"":",提示:"+msg));
		ol.setAdminId(1);
		ol.setEventexplain(eventexplain);
		ol.setCreateTime((new java.util.Date()));
		ol.setUserid(Long.parseLong(Userid));
		ol.setOperResult(flag == true ? "成功" : "失败");
		ol.setIp((String)request.getSession().getAttribute("IP"));
		this.operlogService.insert(ol);
	}
	//endregion
	
	//region  展示玩家数据
	@ResponseBody
	@RequestMapping(value="pa/list",method = RequestMethod.POST,produces="text/html;charset=UTF-8") //防止页面乱码
	public Map list(HttpServletRequest request,String pageIndex,String pageCount,String UserId,String field,String order,String Businessman)throws Exception{
		if(("").equals(UserId.trim())) {
			ButlerGetPlayerInfoListRequest req = new  ButlerGetPlayerInfoListRequest();
		/***
		 * String vip=request.getParameter("vip");
		 * form表格参数传送了进来
		 */
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId"); //区服后面根据登录人的ID,来判断,暂时为1
    	req.PageIndex=Integer.parseInt(pageIndex) - 1;
    	req.PageCount=Integer.parseInt(pageCount);
    	req.FilterBusinessman = Integer.parseInt(Businessman);
    	if(field == "" || field == null) {
    		req.FilterField = 12;
    		req.FilterType = 2;
    	}
    	else {
    		for(Playerlist field3 : Playerlist.values()) {
    			if(field3.name().equals(field)) {
    				req.FilterField = field3.getValue();
    				break;
    			}
    		}
    		if(order.equals("desc")) req.FilterType = 2;
    		else req.FilterType = 1;
    	}
    	ButlerGetPlayerInfoListResponse rsp = new  ButlerGetPlayerInfoListResponse();
    	if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);//发送请求
		if(rsp.PlayerList != null) {
			for(int i = 0;i < rsp.PlayerList.size();i++) {
				rsp.PlayerList.get(i).Integral = rsp.PlayerList.get(i).Integral == 0 ? 0 : rsp.PlayerList.get(i).Integral/10000;
			}
		}
		//获取req的所有申明属性及对象
		/*Field[] reqField = req.getClass().getDeclaredFields();
		for (int i = 0;i < reqField.length;i++) {
			Field f = reqField[i];
			f.setAccessible(true);
			System.out.println(f.getName() + " " + f.get(req));
		}*/
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("status", "200");
		map.put("message", "");
		map.put("data", rsp.PlayerList);
		map.put("count", rsp.TotalCount);
		return map;
		}else {
			Map<String,Object> map = new HashMap<String,Object>();
			ButlerGetPlayerInfoRequest req = new ButlerGetPlayerInfoRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Long.valueOf(UserId.trim());
			ButlerGetPlayerInfoResponse rsp = new ButlerGetPlayerInfoResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "";
			client.Execute(req, rsp);
			//获得object对象对应的所有已申明的属性
			if (rsp.Info != null) {
				Field[] field2 = rsp.Info.getClass().getDeclaredFields();
				JSONObject object = new JSONObject();
				for(int i = 0; i < field2.length; i++) {
					Field f = field2[i];
					f.setAccessible(true);  //当访问类私有变量的value值时，必须要加上
					if(f.getName().equals("Integral") && (long)f.get(rsp.Info) != 0) {
						object.put(field2[i].getName(), (long)f.get(rsp.Info)/10000);
						continue;
					}
					//当值为null时 给值设定为空字符串
					if(f.get(rsp.Info) == null) {
						object.put(field2[i].getName(), "");
						continue;
					}
					object.put(field2[i].getName(), f.get(rsp.Info));
				}
				JSONArray array= new JSONArray().fromObject(object);
				List<ButlerPlayerInfoOnline> list = JSONArray.fromObject(array);
				map.put("data", list);
				map.put("count", 1);
				map.put("status", "200");
				map.put("message", "");
				return map;
			}else {
				map.put("data", "");
				map.put("count", 0);
				map.put("status", "202");
				map.put("message", rsp.ErrMsg);
				return map;
			}
		}	
	}
	//endregion
	
	//region 锁定玩家页面
	@RequestMapping("pa/toPlayerBan")
	public ModelAndView PlayerBan(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/player_ban");
		return mav;
	}
	//endregion
	
	//region 锁定玩家
	@ResponseBody
	@RequestMapping(value="pa/player_ban",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public JSONObject player_ban(HttpServletRequest request,String ID,String PageIndex,String PageCount)throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		if("".equals(ID)) {
		ButlerBlockAccountGetAllRecordsRequest req = new ButlerBlockAccountGetAllRecordsRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.PageCount=Integer.parseInt(PageCount);
		req.PageIndex=Integer.parseInt(PageIndex) - 1;
		ButlerBlockAccountGetAllRecordsResponse rsp = new ButlerBlockAccountGetAllRecordsResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		List<ButlerBlockAccountInfo> lst = rsp.Records;
		if(lst != null) {
			map.put("data",lst);
			map.put("count",lst.size());
		}else {
			map.put("data", "");
			map.put("count",0);
		}
		//需要去改
		map.put("message","");
		map.put("status", "200");
		JSONObject json  = new JSONObject(map);
		return json;//输出为string格式
		}else {
			ButlerBlockAccountGetPlayerRecordsRequest req = new ButlerBlockAccountGetPlayerRecordsRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(ID);
			ButlerBlockAccountGetPlayerRecordsResponse rsp = new ButlerBlockAccountGetPlayerRecordsResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			List<ButlerBlockAccountAction> lst = rsp.PlayerRecords;
			map.put("data",lst);
			//需要去改
			map.put("count",lst.size());
			map.put("message", "");
			map.put("status", "200");
			JSONObject json  = new JSONObject(map);
			return json;//输出为string格式
		}
	}
	//endregion
	
	//region 文本框数字转为汉字提示
	@ResponseBody
	@RequestMapping(value="pa/NumberTransfrom",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String NumberTransfrom(HttpServletRequest request,String number)throws Exception{
		String i = com.fishing.util.NumberTransfrom.transfrom(number);
        return i;
	}
	//endregion
	
	//region 分类
	@RequestMapping("pa/detail/{type}")
	public ModelAndView detail(@PathVariable("type")String type, Long userId, Long srcUserId, Long toUserId, HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/detail_"+type);
		return mav;
	}
	//endregion
	
	
	//region 锁定或者解锁用户
	@ResponseBody
	@RequestMapping(value="pa/updateLocked",method = RequestMethod.POST,produces="text/html;charset=UTF-8") //防止页面乱码
	public String updateLocked(String formdata,HttpServletRequest request)throws Exception{  
		//System.out.println(formdata);  //感谢    https://www.cnblogs.com/move22/p/7376315.html
		L_player player = JSON.parseObject(formdata,L_player.class); //json字符串转java对象
		if(player.getUpdateBlock().equals("解封")) {
			ButlerBlockAccountRemoveRequest req = new ButlerBlockAccountRemoveRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId=Integer.valueOf(player.getUserId().trim());
			req.OperationReason=player.getOperatReason();
			req.Operator=(String)request.getSession().getAttribute("Admintruename");
			ButlerBlockAccountRemoveResponse rsp = new ButlerBlockAccountRemoveResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.ErrMsg == null) {
				insertLog(true, "", 2, "解封玩家", String.valueOf(req.UserId), request);
				return "解封成功";
			}else {
				insertLog(false, "", 2, "解封玩家", String.valueOf(req.UserId), request);
				return rsp.ErrMsg;
			}
		}
		if(player.getUpdateBlock().equals("封禁")) {
			ButlerBlockAccountAddRequest req = new ButlerBlockAccountAddRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId=Integer.valueOf(player.getUserId().trim());
			req.BlockType=1;
			req.BlockDuration=0;
			req.OprationReason=player.getOperatReason();
			req.Operator=(String)request.getSession().getAttribute("Admintruename");
			ButlerBlockAccountAddResponse rsp = new ButlerBlockAccountAddResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.ErrMsg == null) {
				insertLog(true, "", 2, "封禁玩家", String.valueOf(req.UserId), request);
				return "封禁成功";
			}else {
				insertLog(false, "", 2, "封禁玩家", String.valueOf(req.UserId), request);
				return rsp.ErrMsg;
			}
		}
		return null;
	}
	//endregion
	
	//region 查询玩家资源变动日志
	@ResponseBody
	@RequestMapping(value="pa/playerResourceLog",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public JSONObject playerResourceLog(String UserId,String StartTime,String EndTime,String PageIndex,String PageCount,String LogType,String ItemName,String Reasons,HttpServletRequest request)throws Exception {
		Map map = new HashMap();
		ButlerGetPlayerResourceLogRequest req = new ButlerGetPlayerResourceLogRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.UserId=Integer.valueOf(UserId.trim());
		req.StartTime=StartTime;
		req.EndTime= EndTime;
		req.PageIndex=Integer.valueOf(PageIndex);
		req.PageCount=Integer.valueOf(PageCount);
		req.ItemName = ItemName;
		req.Reasons = Reasons;
		ButlerGetPlayerResourceLogResponse rsp = new ButlerGetPlayerResourceLogResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		List<ButlerPlayerResourceLog> lst = rsp.LogItems;//调用数据
		map.put("data", lst);
		map.put("count", rsp.TotalCount);
		map.put("message", "");
		map.put("status", "200");
		JSONObject json = new JSONObject(map);
		return json;//输出为string格式
	}
	//endregion
	
	/***
	 * @param userId 用户ID
	 * @param DifficultLevel 控制难度
	 * @param TargetFraction 目标分数
	 * @return
	 * @throws Exception
	 */
	//region 调整玩家难度
	@ResponseBody
	@RequestMapping(value="pa/PlayerAdjustment",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String PlayerAdjustment(HttpServletRequest request,String userId,String DifficultLevel,String TargetFraction)throws Exception {
		//检测
		if((Integer.parseInt(DifficultLevel) <=2 && Integer.parseInt(DifficultLevel) >=0) && 1 == 1) {
			
		}
		
		ButlerPlayerDifficultySetRequest req = new ButlerPlayerDifficultySetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.UserId = Integer.parseInt(userId.trim());
        //上分或者下分
		/*if(ContrlDifficulty.equals("2")) {
        	req.Degree = Integer.parseInt(slideNumber);
        }else {
        	if(slideNumber.equals("")) {
        		req.Degree = 0;
        	}else {
        		req.Degree = -Integer.parseInt(slideNumber);
        	}
        }*/
		req.DifficultyLevel = Integer.parseInt(DifficultLevel);
        req.DestCurrency = Long.parseLong(TargetFraction);
        ButlerPlayerDifficultySetResponse rsp = new ButlerPlayerDifficultySetResponse();
        insertLog(true, "", 2, (req.DifficultyLevel <=2 ) ? "下分":(req.DifficultyLevel >=4 ) ? "上分": "取消控制", String.valueOf(req.UserId), request);
        if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		return rsp.ErrMsg;//输出为string格式
	}
    //endregion
	
	//region 在线用户页面
	@RequestMapping("player/online")
	public ModelAndView online(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("player/online_list");
		return mav;
	}
	//endregion
	
	//region 加载玩家资源物品下拉框
	@ResponseBody
	@RequestMapping(value="pa/GoodsSelectone",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String selectone(HttpServletRequest request) {
		ButlerGetAllItemNamesRequest req = new ButlerGetAllItemNamesRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerGetAllItemNamesResponse rsp = new ButlerGetAllItemNamesResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		StringBuilder sb = new StringBuilder();
		sb.append("[{");
		char  j = '"';
		int m = 0;
		//String 转 数组
		String[] arry = rsp.ItemNames.split(","); //用,分割 
		for(int i = 0;i < rsp.ItemNames.length();i++) {
			if( ',' == rsp.ItemNames.charAt(i)) {
				sb.append('"');
                sb.append(":");
                sb.append('"');
                sb.append(arry[m]);
                sb.append('"');
                m = m + 1;
                sb.append(",");
				sb.append('"');
			}else if(i == 0){
				sb.append('"');
				sb.append(rsp.ItemNames.charAt(i));
			}else {
				sb.append(rsp.ItemNames.charAt(i));
			}
		}
		sb.append('"');
		sb.append(":");
		sb.append('"');
		sb.append(arry[arry.length-1]);
		sb.append('"');
		sb.append("}]");
		return sb.toString();
	}
	//endregion
	
	//region 加载资源变动原因
	@ResponseBody
	@RequestMapping(value="pa/ReasonsSelectone",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    public net.sf.json.JSONArray ReasonsSelectone(HttpServletRequest request,String ChooseGoods) throws Exception {
		ButlerGetResourceChangeReasonMapRequest req = new ButlerGetResourceChangeReasonMapRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerGetResourceChangeReasonMapResponse rsp = new ButlerGetResourceChangeReasonMapResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		List ItemReasonList = new ArrayList();
		Map<String,String> map = new HashMap<String,String>();
		ItemReasonList = rsp.ItemReasonList;
		String js = JsonUtils.obj2json(ItemReasonList);
		List<ButlerResourceChangeReasonItem> arraylist = JSON.parseArray(js, ButlerResourceChangeReasonItem.class);
		if(ChooseGoods == null || ChooseGoods.equals("")) {
		for(int i = 0; i < arraylist.size(); i++) {
			String[] strArr = arraylist.get(i).Reasons.split(",");
			for(int s = 0;s < strArr.length; s++) {
				map.put(strArr[s], strArr[s]);
			}
		}
		net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(map);
		return json;
		}
		else {
			//如果ChooseGoods不为空，列出ChooseGoods下面的选项
			for(int i = 0; i < arraylist.size(); i++) {
				if(arraylist.get(i).Name.equals(ChooseGoods)) {
					String[] strArr = arraylist.get(i).Reasons.split(",");
					for(int s = 0;s < strArr.length; s++) {
						map.put(strArr[s], strArr[s]);
					}
				}
			}
			net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(map);
			return json;

		}
		/*if(ChooseGoods.equals("锤子碎片")) {
			for(int i = 0; i < arraylist.size(); i++) {
				if(arraylist.get(i).Name.equals("锤子碎片")) {
					String[] strArr = arraylist.get(i).Reasons.split(",");
					for(int s = 0;s < strArr.length; s++) {
						map.put(strArr[s], strArr[s]);
					}
				}
			}
			net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(map);
			return json;
		}*/
		
	}
	//endregion
	
	//region 玩家资源变化列表
	@ResponseBody
	@RequestMapping(value="pa/ResourceReason",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public Map ResourceReason(HttpServletRequest request,String UserID,String ChooseGoods,String ChangeReason,String startTime,String endTime,String PageIndex,String PageCount) throws Exception {
		ButlerGetPlayerResourceLogRequest req = new ButlerGetPlayerResourceLogRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		long count = 0;
		if(("").equals(ChooseGoods) && ("").equals(ChangeReason) && (startTime).equals(endTime) && ("").equals(startTime)) {
			Date  date1 = new Date();//这是用来刚打开页面默认加载当天时间
			SimpleDateFormat date2 = new SimpleDateFormat ("yyyy-MM-dd");
//			System.out.println("userid: "+UserID);
			req.UserId = Integer.parseInt(UserID.trim());
			req.StartTime = date2.format(date1);
			req.EndTime = date2.format(date1.getTime() + 60*60*1000*24);
			req.PageIndex = Integer.parseInt(PageIndex) -1;
			req.PageCount = Integer.parseInt(PageCount);
			req.ItemName = ChooseGoods;
			req.Reasons = ChangeReason;
			ButlerGetPlayerResourceLogResponse rsp = new ButlerGetPlayerResourceLogResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("data", rsp.LogItems);
			resultMap.put("count", rsp.TotalCount);
			resultMap.put("message", "");
			resultMap.put("status", "200");
			return resultMap;
		}else {
			req.UserId = Integer.parseInt(UserID.trim());
			req.StartTime = startTime;
			req.EndTime = endTime;
			if(("").equals(startTime)) {
				Date  date1 = new Date();//这是用来刚打开页面默认加载当天时间
				SimpleDateFormat date2 = new SimpleDateFormat ("yyyy-MM-dd");
				req.StartTime = date2.format(date1);
			}
			if(("").equals(endTime)) {
				Date  date1 = new Date();//这是用来刚打开页面默认加载当天时间
				SimpleDateFormat date2 = new SimpleDateFormat ("yyyy-MM-dd");
				req.EndTime = date2.format(date1.getTime() + 60*60*1000*24);
			}
			req.PageIndex = Integer.parseInt(PageIndex) - 1;
			req.PageCount = Integer.parseInt(PageCount);
			req.ItemName = ChooseGoods;
			req.Reasons = ChangeReason;
			ButlerGetPlayerResourceLogResponse rsp = new ButlerGetPlayerResourceLogResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("data", rsp.LogItems);
			resultMap.put("count", rsp.TotalCount);
			resultMap.put("message", "");
			resultMap.put("status", "200");
			return resultMap;
		}
	}
	//endregion
	
	//region 展示在线玩家数据
	@ResponseBody
	@RequestMapping(value="pa/onlinelist",method = RequestMethod.POST,produces="text/html;charset=UTF-8") //防止页面乱码
	public JSONObject onlinelist(HttpServletRequest request,String UserId,String PageIndex,String PageCount
			                     ,String Room,String order,String field,String Businessman)throws Exception{  
		Map<String,Object> map = new HashMap<String,Object>();
		if(null == UserId || ("").equals(UserId)) {
			ButlerGetPlayerInfoOnlineListRequest req = new ButlerGetPlayerInfoOnlineListRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.PageIndex = Integer.parseInt(PageIndex) - 1;
			req.PageCount = Integer.parseInt(PageCount);
			if(field == "" || field == null) {
			    req.FilterField = 0;
			    req.FilterType = 2;
			}else {
				for(SortField sortfield : SortField.values()) {
					if(sortfield.name().equals(field)) {
						req.FilterField = sortfield.getValue();
						break;
					}
				}
				if(order.equals("desc")) req.FilterType = 2;
	    		else req.FilterType = 1;
			}
			req.FilterRoom = Room;
			req.FilterBusinessman = Integer.parseInt(Businessman);
			ButlerGetPlayerInfoOnlineListResponse rsp = new ButlerGetPlayerInfoOnlineListResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.PlayerList == null) {
				String[] zero = {};
				List<String> zeroList = Arrays.asList(zero);
				map.put("data", zeroList);
			}else {
				for(int i = 0;i < rsp.PlayerList.size();i++) {
					rsp.PlayerList.get(i).Integral = rsp.PlayerList.get(i).Integral ==  0 ? 0 : rsp.PlayerList.get(i).Integral/10000;
				}
			    map.put("data", rsp.PlayerList);
			}
			map.put("count", rsp.TotalCount);
			map.put("status", "200");
			map.put("message", "");
			JSONObject json = new JSONObject(map);
			return json;
		}else{
			ButlerGetPlayerInfoOnlineRequest req = new ButlerGetPlayerInfoOnlineRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(UserId.trim());
			ButlerGetPlayerInfoOnlineResponse rsp = new ButlerGetPlayerInfoOnlineResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.Info == null) {
				map.put("status", "202");
			    map.put("message", rsp.ErrMsg);
			    map.put("count", 0);
			    map.put("data","");
			    JSONObject json = new JSONObject(map);
			    return  json;
			}else {
			Field[] field2 = rsp.Info.getClass().getDeclaredFields();
			JSONObject object = new JSONObject();
			for(int i = 0; i < field2.length; i++) {
				Field f = field2[i];
				f.setAccessible(true);  //当访问类私有变量的value值时，必须要加上
				if(f.getName().equals("Integral") && (long)f.get(rsp.Info) != 0) {
					object.put(field2[i].getName(), (long)f.get(rsp.Info)/10000);
					continue;
				}
				//当值为null时 给值设定为空字符串
				if(f.get(rsp.Info) == null) {
					object.put(field2[i].getName(), "");
					continue;
				}
				object.put(field2[i].getName(), f.get(rsp.Info));
			}
			JSONArray array= new JSONArray().fromObject(object);
			List<ButlerPlayerInfoOnline> list = JSONArray.fromObject(array);
			map.put("data", list);
			map.put("count", Integer.parseInt(PageCount));
			map.put("status", "200");
			map.put("message", "");
		    JSONObject json = new JSONObject(map);
			return json;
			}
		}
	}
	//endregion
	
	//region 在线玩家所在房间
	@ResponseBody
	@RequestMapping(value="playeronline/room",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public net.sf.json.JSONArray  room(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<>();
		try {
			ButlerGetPlayerOnlineLocationListRequest req = new ButlerGetPlayerOnlineLocationListRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			ButlerGetPlayerOnlineLocationListResponse rsp = new ButlerGetPlayerOnlineLocationListResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://118.24.113.66:8000/router/rest";
			client.Execute(req, rsp);
			String[] strArr = rsp.LocationString.split(",");
			for(int s = 0;s < strArr.length; s++) {
				map.put(strArr[s], strArr[s]);
			}
			net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(map);
			return json;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	//endregion
	
	//region 设置商人
	@ResponseBody
	@RequestMapping(value="Player/setBusinessman",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String setBusinessman(HttpServletRequest request,String username,Boolean Businessman) throws Exception {
		ButlerAccountBusinessManSetRequest req = new ButlerAccountBusinessManSetRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(username.trim());
			req.Businessman = Businessman;
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountBusinessManSetResponse  rsp = new ButlerAccountBusinessManSetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "设置商人", String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, "设置商人", String.valueOf(req.UserId), request);
			return "fail";
		}
	}
	//endregion
	
	//region 设置VIP经验
	@ResponseBody
	@RequestMapping(value="Player/setVip",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String setVip(HttpServletRequest request,String username,String VipExpAddition) throws Exception {
		ButlerPlayerAddVipExpRequest req = new ButlerPlayerAddVipExpRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(username.trim());
			req.VipExpAddition = Integer.parseInt(VipExpAddition);
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerPlayerAddVipExpResponse  rsp = new ButlerPlayerAddVipExpResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, (req.VipExpAddition > 0)?"增加Vip经验"+req.VipExpAddition:"减少Vip经验"+req.VipExpAddition, String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, (req.VipExpAddition > 0)?"增加Vip经验"+req.VipExpAddition:"减少Vip经验"+req.VipExpAddition, String.valueOf(req.UserId), request);
			return "fail";
		}
	}
	//endregion
	
	//region 修改绑定手机，密码
	@ResponseBody
	@RequestMapping(value="player/changePhone",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String changePhone(HttpServletRequest request,String username,String phone,String password) throws Exception {
		//后台检测
		if(phone.length() != 11) 
			return "手机号码长度要为11位";
		if(password.length() < 6 || password.length() > 20)
			return "密码长度不低于6位，不高于20位";
		try {
			//Pattern.compile用于编译正则表达式并生产一个Pattern对象。这个Pattern对象可以判断某个给定的字符串是否匹配此正则表达式
			java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
			Matcher isNum = pattern.matcher(phone);
		    if (!isNum.matches())
		    	return "手机号码要为数字";
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ButlerAccountBindPhoneRequest req = new ButlerAccountBindPhoneRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(username.trim());
			req.Phone = phone;
			req.Password = password;
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountBindPhoneResponse rsp = new ButlerAccountBindPhoneResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "更改玩家绑定手机号码", String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, "更改玩家绑定手机号码", String.valueOf(req.UserId), request);
			return rsp.ErrMsg;
		}
	}
	//endregion
	
	//region 修改用户金库密码
	@ResponseBody
	@RequestMapping(value="player/changeBankPassword",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String changeBankPassword(HttpServletRequest request,String username,String password) throws Exception {
		//后台检测
		if(password.length() != 6) 
			return "金库密码为6位";
		try {
			//Pattern.compile用于编译正则表达式并生产一个Pattern对象。这个Pattern对象可以判断某个给定的字符串是否匹配此正则表达式
			java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
			Matcher isNum = pattern.matcher(password);
		    if (!isNum.matches())
		    	return "金库密码要为数字";
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ButlerAccountResetBankPasswordRequest req = new ButlerAccountResetBankPasswordRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(username.trim());
			req.Password = password;
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountResetBankPasswordResponse rsp = new ButlerAccountResetBankPasswordResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "更改玩家金库密码", String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, "更改玩家金库密码", String.valueOf(req.UserId), request);
			return rsp.ErrMsg;
		}
	}
	//endregion
	
	//region 修改用户手机登录密码
	@ResponseBody
	@RequestMapping(value="player/UpdateAccountResetPhonePassword",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String UpdateAccountResetPhonePassword(HttpServletRequest request,String Phone,String password) throws Exception {
		//后台检测
		if(Phone.length() != 11) 
			return "手机号码长度要为11位";
		if(password.length() < 6 || password.length() > 20)
			return "密码长度不低于6位，不高于20位";
		try {
			//Pattern.compile用于编译正则表达式并生产一个Pattern对象。这个Pattern对象可以判断某个给定的字符串是否匹配此正则表达式
			java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
			Matcher isNum = pattern.matcher(password);
		    if (!isNum.matches())
		    	return "金库密码要为数字";
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ButlerAccountResetPhonePasswordRequest req = new ButlerAccountResetPhonePasswordRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.Phone  = Phone; 
			req.Password = password;
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountResetPhonePasswordResponse rsp = new ButlerAccountResetPhonePasswordResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "更改玩家绑定手机号码", "0", request);
			return "success";
		}else {
			insertLog(false, "", 2, "更改玩家绑定手机号码", "0", request);
			return rsp.ErrMsg;
		}
	}
	//endregion
	
	//region 指定手机号创建账号
	@ResponseBody
	@RequestMapping(value="player/AccountPhoneGenerate",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String AccountPhoneGenerate(HttpServletRequest request,String phone,long userId,String password) throws Exception {
		//后台检测
		if(phone.trim().length() != 11) 
			return "手机号码长度要为11位";
		if(String.valueOf(userId).length() < 7 ||  String.valueOf(userId).length() > 8) 
			return "游戏号长度要大于7位或者小于8位";
		if(password.trim().length() < 6 || password.trim().length() > 20)
			return "密码长度不低于6位，不高于20位";
		try {
			//Pattern.compile用于编译正则表达式并生产一个Pattern对象。这个Pattern对象可以判断某个给定的字符串是否匹配此正则表达式
			java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
			Matcher isNum = pattern.matcher(password.trim());
		    if (!isNum.matches())
		    	return "密码要为数字";
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ButlerAccountPhoneGenerateRequest req = new ButlerAccountPhoneGenerateRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.Phone  = phone.trim();
			req.UserId = userId;
			req.Password = password.trim();
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountPhoneGenerateResponse rsp = new ButlerAccountPhoneGenerateResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://localhost:3875/";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "创建手机账号", "0", request);
			return "success";
		}else {
			insertLog(false, "", 2, "创建手机账号", "0", request);
			return rsp.ErrMsg;
		}
	}
	//endregion
	
	//region 批量创建账号
	@ResponseBody
	@RequestMapping(value="player/AccountPhoneBatchGenerate",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public Object AccountPhoneBatchGenerate(HttpServletRequest request,String prefixNumber,String password,String Count) throws Exception {
		//后台检测
		if(!(Integer.parseInt(Count.trim()) <= 100 && Integer.parseInt(Count.trim()) >= 1)) 
			return "生成数量在1-100之间";
		if(password.trim().length() < 6 || password.trim().length() > 20)
			return "密码长度不低于6位，不高于20位";
		if(!(Integer.parseInt(prefixNumber.trim()) <= 9 && Integer.parseInt(prefixNumber.trim()) >= 2)) 
			return "账号前缀在2-9之间";
		try {
			//Pattern.compile用于编译正则表达式并生产一个Pattern对象。这个Pattern对象可以判断某个给定的字符串是否匹配此正则表达式
			java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
			Matcher isNum = pattern.matcher(password.trim());
		    if (!isNum.matches())
		    	return "金库密码要为数字";
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ButlerAccountPhoneBatchGenerateRequest req = new ButlerAccountPhoneBatchGenerateRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.Amount = Integer.parseInt(Count.trim());
			req.Prefix = prefixNumber.trim();
			req.Password = password.trim();
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerAccountPhoneBatchGenerateResponse rsp = new ButlerAccountPhoneBatchGenerateResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			Map<String,Object> map2 = new HashMap<>();
			List<Map> list = new ArrayList<>();
			JSONArray jsonarry = JSONArray.fromObject(rsp.PhoneList.split(","));
			for(int i = 0;i < rsp.PhoneList.split(",").length;i++) {
				Map<String,Object> map = new HashMap<>();
				map.put("Phone", jsonarry.get(i));
				map.put("password", password);
				list.add(map);
			}
			map2.put("data", list);
			map2.put("count", rsp.PhoneList.split(",").length);
			map2.put("status", "200");
			map2.put("message", "");
			insertLog(true, "", 2, "批量创建手机账号", "0", request);
			return map2;
		}else {
			insertLog(false, "", 2, "批量创建手机账号", "0", request);
			return rsp.ErrMsg;
		}
	}
	//endregion

	//region 设置个人奖池
	@ResponseBody
	@RequestMapping(value="Player/SetPool", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String SetPool(HttpServletRequest request, String username, String ChangeValue) throws Exception {
		//检测字符串是否是数字
		if (!(RegExrUtils.isNumber(username.trim()) && RegExrUtils.isNumber(ChangeValue.trim()))) {
			return "个人奖池请输入纯数字";
		}
		//发送参数
		ButlerPlayerPrizePoolAddRequest req = new ButlerPlayerPrizePoolAddRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.UserId = Integer.parseInt(username.trim());
		req.Delta  = Integer.parseInt(ChangeValue.trim());
		ButlerPlayerPrizePoolAddResponse rsp = new ButlerPlayerPrizePoolAddResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		//处理结果
		if(rsp.ErrMsg != null || rsp.ErrMsg != "") {
			insertLog(true, "", 2, (req.Delta >=0)?"加个人奖池"+req.Delta:"减个人奖池"+req.Delta, String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, (req.Delta >=0)?"加个人奖池"+req.Delta:"减个人奖池"+req.Delta, String.valueOf(req.UserId), request);
			return "fail";
		}
	}
	//endregion
	
	//region 设置玩家难度
	@ResponseBody
	@RequestMapping(value="Player/SetPlayerDifficult", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String SetPlayerDifficult(HttpServletRequest request, String username, String DestCurrency, String DifficultSet) throws Exception {
		//检测字符串是否是数字
		if (!(RegExrUtils.isNumber(username.trim())     && 
			  RegExrUtils.isNumber(DestCurrency.trim()) && 
			  RegExrUtils.isNumber(DifficultSet.trim()))) {
			return "请输入纯数字";
		}
		//难度对应上下分
		if(((Integer.parseInt(DifficultSet.trim()) <=2 && Integer.parseInt(DifficultSet.trim()) >=0) && Integer.parseInt(DestCurrency.trim()) > 0)
				||
		   ((Integer.parseInt(DifficultSet.trim()) <=6 && Integer.parseInt(DifficultSet.trim()) >=4) && Integer.parseInt(DestCurrency.trim()) < 0)
			) {
			return "请输入正确的难度及输赢分数";
		}
		
		ButlerPlayerDifficultySetRequest req = new ButlerPlayerDifficultySetRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.UserId = Integer.parseInt(username.trim());
		req.DifficultyLevel = Integer.parseInt(DifficultSet.trim());
		req.DestCurrency = Integer.parseInt(DestCurrency.trim());
		ButlerPlayerDifficultySetResponse rsp = new ButlerPlayerDifficultySetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		
		if(rsp.ErrMsg != null || rsp.ErrMsg != "") {
			insertLog(true, "", 2, ((Integer.parseInt(DifficultSet.trim()) <=2 && Integer.parseInt(DifficultSet.trim()) >=0))?"减小玩家难度":((Integer.parseInt(DifficultSet.trim()) <=6 && Integer.parseInt(DifficultSet.trim()) >=4))?"增加玩家难度":"取消玩家难度", String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, ((Integer.parseInt(DifficultSet.trim()) <=2 && Integer.parseInt(DifficultSet.trim()) >=0))?"减小玩家难度":((Integer.parseInt(DifficultSet.trim()) <=6 && Integer.parseInt(DifficultSet.trim()) >=4))?"增加玩家难度":"取消玩家难度", String.valueOf(req.UserId), request);
			return "fail";
		}
	}
	//endregion
	
	//region 修改玩家昵称
	@ResponseBody
	@RequestMapping(value="player/changenickname",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String changenickname(HttpServletRequest request,String username,String nickname) throws Exception {
		
		ButlerPlayerNicknameModifyRequest req = new ButlerPlayerNicknameModifyRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(username);
			req.NewNickname = nickname;
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerPlayerNicknameModifyResponse rsp = new ButlerPlayerNicknameModifyResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "更改玩家昵称"+req.NewNickname, String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, "更改玩家昵称"+req.NewNickname, String.valueOf(req.UserId), request);
			return rsp.ErrMsg;
		}
	}
	//endregion
	
	//region 重置修改昵称次数
	@ResponseBody
	@RequestMapping(value="player/resetchangenickname",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public String resetchangenickname(HttpServletRequest request,String userid) throws Exception {
		
		ButlerPlayerNicknameModifyCountResetRequest req = new ButlerPlayerNicknameModifyCountResetRequest();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = Integer.parseInt(userid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		ButlerPlayerNicknameModifyCountResetResponse rsp = new ButlerPlayerNicknameModifyCountResetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		if(rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			insertLog(true, "", 2, "重置玩家昵称修改次数", String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, "重置玩家昵称修改次数", String.valueOf(req.UserId), request);
			return rsp.ErrMsg;
		}
	}
	//endregion
    
	//region 修改玩家资源
	@ResponseBody
	@RequestMapping(value="player/UpdatePlayerResource", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public String UpdatePlayerResource(HttpServletRequest request, int ResourceType, String ItemName, String Count,String username) throws Exception {
		//检测字符串是否是数字
		if (!(RegExrUtils.isNumber(Count) &&
			  RegExrUtils.isNumber(username))) {
			return "请输入纯数字";
		}
		if (!(ResourceType == 1 || ResourceType == 2)) {
			return "请选择正确资源类型";
		}
		ButlerPlayerResourceAddRequest req = new ButlerPlayerResourceAddRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.UserId = Integer.parseInt(username);
		req.ResourceType = ResourceType;
		req.ItemName = ItemName;
		req.Delta = Long.parseLong(Count);
		req.Operater = (String)request.getSession().getAttribute("Admintruename");
		ButlerPlayerResourceAddResponse rsp = new ButlerPlayerResourceAddResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		
		if(rsp.ErrMsg == "" || rsp.ErrCode == null) {
			insertLog(true, "", 2, req.Delta < 0?"减少玩家"+req.ItemName+req.Delta:"增加"+req.ItemName+req.Delta, String.valueOf(req.UserId), request);
			return "success";
		}else {
			insertLog(false, "", 2, req.Delta < 0?"减少玩家"+req.ItemName+req.Delta:"增加"+req.ItemName+req.Delta, String.valueOf(req.UserId), request);
			return rsp.ErrMsg;
		}
	}
	//endregion

    //region 查询玩家资源修改日志
	@ResponseBody
	@RequestMapping(value="player/UpdatePlayerResourceLog", method = RequestMethod.POST, produces="text/html;charset=UTF-8")
	public Map<String,Object> UpdatePlayerResourceLog(HttpServletRequest request, String UserId, int ResourceType,String pageIndex,String pageCount) throws Exception {
		Map<String,Object> map = new HashMap<>();
		
		ButlerPlayerResourceAddLogQueryRequest req = new ButlerPlayerResourceAddLogQueryRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		if (UserId == "") 
			req.FilterUserId = 0;
		else 
			req.FilterUserId = Integer.parseInt(UserId);
		req.FilterResourceType = ResourceType;
		req.PageIndex = Integer.parseInt(pageIndex) -1;
		req.PageCount = Integer.parseInt(pageCount);
		ButlerPlayerResourceAddLogQueryResponse rsp = new ButlerPlayerResourceAddLogQueryResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://118.24.113.66:8000/router/rest";
		client.Execute(req, rsp);
		
		if(rsp.ErrMsg != null || rsp.ErrMsg != "") {
			insertLog(true, "", 2, "查询玩家修改资源日志", String.valueOf(req.FilterUserId), request);
			map.put("data", rsp.Logs);
			map.put("count", rsp.TotalCount);
			map.put("status", "200");
			map.put("message", "");
			return map;
		}else {
			insertLog(false, "", 2, "查询玩家修改资源日志", String.valueOf(req.FilterUserId), request);
			map.put("data", "");
			map.put("count", 0);
			map.put("status", "200");
			map.put("message", "");
			return map;
		}
	}
	//endregion

	//region 转向修改玩家资源页面
	@RequestMapping("pa/view/updatePlayResourceView")
	public ModelAndView updatePlayResourceView(){
		return new ModelAndView("player/UpdatePlayerResource");
	}
	//endregion

	//region 转向玩家资源页面
	@RequestMapping("pa/view/queryPlayResourceView")
	public ModelAndView queryPlayResourceView(){
		return new ModelAndView("player/detail_resourceRecords");
	}
	//endregion
}
